#include "sys/alt_alarm.h"
#include "mythread.h"

/********** defines          **********/

/********** global variables **********/
alt_alarm my_alarm;

/********** functions        **********/

/* The interrupt handler  */
alt_u32 myinterrupt_handler( )
{
  alt_printf("Interrupted by the timer!\n");
  return alt_ticks_per_second();
}

/* Our operating system */
void prototype_os()
{
  int j;
  j = 0;
  /* The timer :
   * This call will interrupt the prototype_os() function
   * one time per second
   * and launch the function myinterrupt_handler()
   * with the parameter NULL
   */
  alt_alarm_start(&my_alarm,
		  alt_ticks_per_second(),
		  myinterrupt_handler,
		  NULL);
  
  //main job of prototype_os()
  while (1)
    {
	  mythread(1);
      alt_printf("This is the prototype os for my exciting CSE351 course projects!\n");
      for (j = 0 ; j < MAX; j++);
    }
}

/********** main            **********/
int main()
{
  //run the function prototype_os()
  prototype_os( );
  return 0;
}
